package com.cloudOffice.handler;

import com.cloudOffice.execption.CustomException;
import com.cloudOffice.execption.SystemException;
import com.cloudOffice.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @program: cloud-office
 * @className: GlobalExceptionHandler
 * @description: 全局异常处理类
 * @data: 2024/2/5 20:22
 * @author: ihu
 * @version: 1.0
 **/

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
	
	/**
	 * 全局异常处理
	 */
	@ExceptionHandler(Exception.class)
	public Result<?> exceptionHandler(Exception e) {
		log.error("Exception全局异常：{}", e.getMessage());
		return Result.fail().message(e.getMessage());
	}

//	@ExceptionHandler(ArithmeticException.class)
//	public Result error(ArithmeticException e) {
//		log.error("ArithmeticException异常处理：{}", e.getMessage());
//		return Result.fail().message(e.getMessage());
//	}
	
	@ExceptionHandler(CustomException.class)
	public Result<?> error(CustomException e) {
		log.error("CustomException异常：{}", e.getMessage());
		return Result.fail().message(e.getMessage()).code(e.getCode());
	}
	
	@ExceptionHandler(SystemException.class)
	public Result<?> error(SystemException e) {
		log.error("CustomException异常：{}", e.getMessage());
		return Result.fail().message(e.getMessage()).code(e.getCode());
	}
}